//
// Created by lenovo on 2022/3/11.
//

#include <android/api-level.h>
#include "TraceDumper.h"
#define PROP_VALUE_MAX  92
#define PROP_SDK_NAME "ro.build.version.sdk"

namespace AnrChecker {

    static bool isHooking = false;
    static bool fromMyPrintTrace = false;

    TraceDumper::TraceDumper() {
    }

    int TraceDumper::getApiLevel() {
        char buf[PROP_VALUE_MAX];
        int len = __system_property_get(PROP_SDK_NAME, buf);
        if (len <= 0) {
            return 0;
        }
        return atoi(buf);
    }

    void TraceDumper::hookAnrTraceWrite(bool isSiUser) {
        int apiLevel = getApiLevel();
        if (apiLevel < 19) {
            return;
        }
        if (!fromMyPrintTrace && isSiUser) {
            return;
        }
        if (isHooking) {
            return;
        }
        isHooking = true;
    }

    void TraceDumper::unHookAnrTraceWrite() {

    }

    TraceDumper::~TraceDumper() {

    }
}
